home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 6890 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  2.6 KB

  1. Path: ix.netcom.com!netnews
  2. From: billbo@ix.netcom.com (Bill Boland)
  3. Newsgroups: comp.os.ms-windows.programmer.tools.mfc,comp.lang.c++,comp.lang.basic.visual.misc
  4. Subject: Re: Prob calling VC++ 4.0 DLL from VB4 (32bit)
  5. Date: Tue, 20 Feb 1996 10:26:52 GMT
  6. Organization: Netcom
  7. Message-ID: <3129a180.11614278@nntp.ix.netcom.com>
  8. References: <4f7u8h$63q@fountain.mindlink.net>
  9. NNTP-Posting-Host: lbx-ca3-05.ix.netcom.com
  10. X-NETCOM-Date: Tue Feb 20  2:26:58 AM PST 1996
  11. X-Newsreader: Forte Agent .99d/32.182
  12.  
  13. a09748@giant.mindlink.bc.ca (ESSA) wrote:
  14.  
  15. >
  16. >Having a frustrating time trying to call a function in a DLL developed in
  17. >VC++ 4.0 from Visual Basic 4.0 (32bit). I'm getting VB error 49 (bad DLL
  18. >calling convention) from the following simple function ...
  19. >
  20. >In mydll.h
  21. >#define DllExport __declspec(dllexport)
  22. >extern "C" long DllExport TestLongParam(long lParam);
  23. >
  24. >In mydll.cpp
  25. >extern "C" long DllExport TestLongParam(long lParam)
  26. >{
  27. >    TRACE("TestLongParam called with %ld\n", lParam);
  28. >    return(1L);
  29. >}
  30. >
  31. >The Declare in VB is
  32. >Declare Function TestLongParam Lib "MYDLL.DLL" (ByVal lParam As Long) As Long
  33. >
  34. >When I call TestLongParam from VB, I get the TRACE output with the correct 
  35. >value for the passed parameter, but on return, VB gives error 49.
  36. >
  37. >Can anyone sugesst what is wrong with the way I have declared the functions ?
  38. >I have played around with the __stdcall modifier, the WINAPI macro and even
  39. >tried the old obsolete FAR PASCAL with no success.
  40. >
  41. >
  42.  
  43. I may have a clue since I had a similar situation today.
  44. If a DLL is compiled with VB 4.0 WITHOUT a module definition file and
  45. uses  the new __declspec( dllexport ) to declare functions as
  46. exportable, VB4 cannot seem to understand them. At least that is what
  47. I discovered today on my own.
  48.  
  49. I created a small DLL with a function that passes a long value and
  50. returned the long value. For example:
  51.  
  52. #define DllExport    __declspec( dllexport )
  53.  
  54. DllExport DWORD        Test( DWORD data );
  55.  
  56. DWORD
  57. Test( DWORD data )
  58. {
  59.     return data;
  60. }
  61.  
  62. VB4 could not seem to handle this. Yet, if I went back to the
  63. traditional method (FAR PASCAL), used a module definition file and
  64. declared the function name in the EXPORTS section, I had no problem. I
  65. really don't know enough about VB4 or the __declspec( dllexport ) to
  66. know why this is...but as soon as I used an EXPORTS section and a
  67. module definition file, all my problems went away.
  68.  
  69. I hope this helps. I know it's a stab in the dark but it sure did
  70. cause me grief and sounded close to the problem you have encountered.
  71.  
  72. Good luck,
  73.  
  74. Bill Boland
  75. --------
  76. billbo@ix.netcom.com
  77. Just a friendly little hobbit. Master of his domain.
  78.